<template>
  <div class="settings">
    <van-nav-bar safe-area-inset-top placeholder :title="$t('AdvancedSetting')" left-arrow fixed @click-left="onClickLeft" />
    <van-pull-refresh v-model="isLoading" :pulling-text="$t('PullingText')" :loosing-text="$t('PullingText')" :success-text="$t('refreshSuccee')" @refresh="onRefresh">
      <van-collapse class="marginTop15" v-model="activeNames">
        <van-collapse-item :title="$t('Safety')" name="1">
          <safetyVue :deviceType="7" :safety="safety" :key="timer" @getFormData="setSafety"></safetyVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('ReactivePower')" name="2">
          <van-form @submit="powerfactorSubmit">
            <van-field
              :value="factMode"
              :label="$t('ModeSelect')"
              readonly
              clickable
              name="picker"
              input-align="right"
              @click="showPowerFact = true"
            />
            <van-popup v-model="showPowerFact" round position="bottom">
              <van-picker
                show-toolbar
                :columns="powerFactors"
                @cancel="showPowerFact = false"
                @confirm="factModeConfirm"
                :confirm-button-text="$t('OK')"
                :cancel-button-text="$t('Cancel')"
              />
            </van-popup>
            <van-field
              v-if="factModeCode==1||factModeCode==2"
              v-model="P2Value"
              :label="$t('PFValue')"
              type="number"
              show-error
              name="validator"
              input-align="right"
              error-message-align="right"
              clearable
              :rules="[{ validator:fixedTwo1,message: `${$t('Range')}：0.80-1.00` }]"
            />
            <van-field
              v-if="factModeCode==3&&(safety==0||safety==1||safety==2||safety==6||safety==7||safety==9||safety==22||safety==23||safety==24||safety==26||safety==27||safety==28||safety==29||safety==30)"
              v-model="P3Value"
              :label="$t('UpperLimit')"
              type="number"
              show-error
              name="validator"
              input-align="right"
              error-message-align="right"
              clearable
              :rules="[{ validator:fixedTwo2,message: `${$t('Range')}：0.90-1.00` }]"
            />
            <van-field
              v-if="factModeCode==3&&(safety==0||safety==1||safety==2||safety==6||safety==7||safety==9||safety==22||safety==23||safety==24||safety==26||safety==27||safety==28||safety==29||safety==30)"
              v-model="P4Value"
              :label="$t('LowerLimit')"
              type="number"
              show-error
              name="validator"
              input-align="right"
              error-message-align="right"
              clearable
              :rules="[{ validator:fixedTwo2,message: `${$t('Range')}：0.90-1.00` }]"
            />
            <van-field
              v-if="factModeCode==3&&(safety==0||safety==1||safety==2||safety==6||safety==7||safety==9||safety==22||safety==23||safety==24||safety==26||safety==27||safety==28||safety==29||safety==30)"
              v-model="P5Value"
              :label="$t('PowerLow')"
              type="number"
              show-error
              name="validator"
              input-align="right"
              error-message-align="right"
              clearable
              :rules="[{ validator:fixedTwo3,message: `${$t('Range')}：0.00-1.00` }]"
            />
            <van-field
              v-if="factModeCode==3&&(safety==0||safety==1||safety==2||safety==6||safety==7||safety==9||safety==22||safety==23||safety==24||safety==26||safety==27||safety==28||safety==29||safety==30)"
              v-model="P6Value"
              :label="$t('PowerUp')"
              type="number"
              show-error
              name="validator"
              input-align="right"
              error-message-align="right"
              clearable
              :rules="[{ validator:fixedTwo3,message: `${$t('Range')}：0.00-1.00` }]"
            />
            <div class="factorBtnBox">
              <van-button block round>{{$t('Save')}}</van-button>
            </div>
          </van-form>
          <pfLockInPointVue
            :setName="'PfLockInPoint'"
            :setUntil="'%'"
            :setMin="100"
            :setMax="110"
            :valName="'PfLockInPointValue'"
            :subOption="'PfLockInPoint'"
            :setValue.sync="PfLockInPointValue"
            v-if="isPFP&&safety==24"
          ></pfLockInPointVue>
          <pfLockInPointVue
            :setName="'PfLockOutPoint'"
            :setUntil="'%'"
            :setMin="90"
            :setMax="100"
            :valName="'PfLockOutPointValue'"
            :subOption="'PfLockOutPoint'"
            :setValue.sync="PfLockOutPointValue"
            v-if="isPFP&&safety==24"
          ></pfLockInPointVue>
          <pfLockInPointVue
            :setName="$t('wQuVrateUp')"
            :setUntil="'%'"
            :setMin="100"
            :setMax="110"
            :valName="'wQuVrateUpValue'"
            :subOption="'wQuVrateUp'"
            :setValue.sync="wQuVrateUpValue"
            v-if="isQu&&(safety==2||safety==6||safety==7||safety==9||safety==21||safety==22||safety==23||safety==24||safety==26||safety==27||safety==28||safety==29||safety==30)"
          ></pfLockInPointVue>
          <pfLockInPointVue
            :setName="$t('wQuVrateLow')"
            :setUntil="'%'"
            :setMin="90"
            :setMax="100"
            :valName="'wQuVrateLowValue'"
            :subOption="'wQuVrateLow'"
            :setValue.sync="wQuVrateLowValue"
            v-if="isQu&&(safety==2||safety==6||safety==7||safety==9||safety==21||safety==22||safety==23||safety==24||safety==26||safety==27||safety==28||safety==29||safety==30)"
          ></pfLockInPointVue>
          <pfLockInPointVue
            :setName="$t('SetQurangeV1')"
            :setUntil="'%'"
            :setMin="0"
            :setMax="60"
            :valName="'SetQurangeV1Value'"
            :subOption="'SetQurangeV1'"
            :setValue.sync="SetQurangeV1Value"
            v-if="isQu&&(safety==2||safety==22)"
          ></pfLockInPointVue>
          <pfLockInPointVue
            :setName="$t('SetQurangeV4')"
            :setUntil="'%'"
            :setMin="0"
            :setMax="60"
            :valName="'SetQurangeV4Value'"
            :subOption="'SetQurangeV4'"
            :setValue.sync="SetQurangeV4Value"
            v-if="isQu&&(safety==2||safety==22)"
          ></pfLockInPointVue>
          <pfLockInPoint2Vue
            :setName="$t('bQpower_set')"
            :setMin="-10000"
            :setMax="10000"
            :valName="'bQpower_setValue'"
            :subOption="'bQpower_set'"
            :setValue.sync="bQpower_setValue"
            v-if="isQSet&&(safety==2||safety==6||safety==7||safety==9||safety==21||safety==22||safety==23||safety==24||safety==26||safety==27||safety==28||safety==29||safety==30)"
          ></pfLockInPoint2Vue>
        </van-collapse-item>
        <van-collapse-item :title="$t('Grid')" name="3">
          <vacMaxVue
            :setName="$t('OVStage1')"
            :setUntil="'V'"
            :setMin="'100.0'"
            :setMax="'300.0'"
            :valName="'VacMaxValue'"
            :subOption="'VacMax'"
            :setValue.sync="VacMaxValue"
          ></vacMaxVue>
          <vacMaxVue
            :setName="$t('OVStage2')"
            :setUntil="'V'"
            :setMin="'100.0'"
            :setMax="'300.0'"
            :valName="'VacMaxSlowProtectValue'"
            :subOption="'VacMaxSlowProtect'"
            :setValue.sync="VacMaxSlowProtectValue"
            v-if="safety!=32&&safety!=34&&safety!=35&&safety!=36&&safety!=37"
          ></vacMaxVue>
          <vacMaxVue
            :setName="$t('UVStage1')"
            :setUntil="'V'"
            :setMin="'1.0'"
            :setMax="'300.0'"
            :valName="'VacMinValue'"
            :subOption="'VacMin'"
            :setValue.sync="VacMinValue"
          ></vacMaxVue>
          <vacMaxVue
            :setName="$t('UVStage2')"
            :setUntil="'V'"
            :setMin="'1.0'"
            :setMax="'300.0'"
            :valName="'VacMinSlowProtectValue'"
            :subOption="'VacMinSlowProtect'"
            :setValue.sync="VacMinSlowProtectValue"
            v-if="safety!=32&&safety!=34&&safety!=35&&safety!=36&&safety!=37"
          ></vacMaxVue>
          <enablepublicVue
            :setName="$t('OV10MinAvgEnable')"
            :columns="toggleArr"
            :setValue="LocalArr.OV10EnableValue"
            :subOption="'V10MinAvgEnable'"
            v-if="safety!=3&&safety!=8&&safety!=10&&safety!=13&&safety!=14&&safety!=15&&safety!=20&&safety!=21&&safety!=25&&safety!=31&&safety!=38"
          ></enablepublicVue>
          <vacMaxVue
            :setName="$t('OV10minset')"
            :setUntil="'V'"
            :setMin="'100.0'"
            :setMax="'300.0'"
            :valName="'Grid10MinAverageValue'"
            :subOption="'Grid10MinAverage'"
            :setValue.sync="Grid10MinAverageValue"
            v-if="safety!=0&&safety!=1&&safety!=3&&safety!=4&&safety!=8&&safety!=10&&safety!=13&&safety!=14&&safety!=15&&safety!=20&&safety!=21&&safety!=25&&safety!=31"
          ></vacMaxVue>
          <facMaxVue
            :setName="$t('OFStage1')"
            :setUntil="'Hz'"
            :setMin="'45.00'"
            :setMax="'65.00'"
            :valName="'FacMaxValue'"
            :subOption="'FacMax'"
            :setValue.sync="FacMaxValue"
          ></facMaxVue>
          <facMaxVue
            :setName="$t('OFStage2')"
            :setUntil="'Hz'"
            :setMin="'45.00'"
            :setMax="'65.00'"
            :valName="'FacMaxSlowProtectValue'"
            :subOption="'FacMaxSlowProtect'"
            :setValue.sync="FacMaxSlowProtectValue"
            v-if="safety!=32&&safety!=34&&safety!=35&&safety!=36&&safety!=37"
          ></facMaxVue>
          <facMaxVue
            :setName="$t('UFStage1')"
            :setUntil="'Hz'"
            :setMin="'45.00'"
            :setMax="'65.00'"
            :valName="'FacMinValue'"
            :subOption="'FacMin'"
            :setValue.sync="FacMinValue"
          ></facMaxVue>
          <facMaxVue
            :setName="$t('UFStage2')"
            :setUntil="'Hz'"
            :setMin="'45.00'"
            :setMax="'65.00'"
            :valName="'FacMinSlowProtectValue'"
            :subOption="'FacMinSlowProtect'"
            :setValue.sync="FacMinSlowProtectValue"
            v-if="safety!=32&&safety!=34&&safety!=35&&safety!=36&&safety!=37"
          ></facMaxVue>
          <enablepublicVue
            :setName="$t('FreqROCOF')"
            :columns="toggleArr"
            :subOption="'FreqROCOF'"
            :setValue="LocalArr.FreqROCOFValue"
            v-if="safety!=32&&safety!=33&&safety!=34&&safety!=35&&safety!=36&&safety!=37"
          ></enablepublicVue>
          <vacMiddleVue
            :setName="$t('OVStage3')"
            :setUntil="'V'"
            :setMin="'100.0'"
            :setMax="'300.0'"
            :subOption="'VacMiddle_slow_Protect'"
            :setValue.sync="VacMiddleSlowProtectValue"
            v-if="safety==10"
          ></vacMiddleVue>
          <tripFreVue
            :setName="'Trip Fre T'"
            :setUntil="'Ms'"
            :setValue="tripfreValue"
            v-if="safety==9"
          ></tripFreVue>
          <tripFreVue
            :setName="'Trip Volt T'"
            :setUntil="'Ms'"
            :setValue="tripvoltValue"
            v-if="safety==9"
          ></tripFreVue>
          <tripFreVue
            :setName="'Loss of Mains'"
            :setUntil="'Ms'"
            :setValue="lossofmainsValue"
            v-if="safety==9"
          ></tripFreVue>
          <tstartVue
            :setName="'T_Start'"
            :setUntil="'S'"
            :setMin="15"
            :setMax="1000"
            :setValue.sync="TStartValue"
            :subOption="'T_Start'"
          ></tstartVue>
          <enablepublicVue
            :setName="$t('NeutralLine')"
            :columns="NeutralLineArr"
            :subOption="'NLineEnable'"
            :setValue="LocalArr.NeutralLineValue"
          ></enablepublicVue>
          <tstartVue
            :setName="$t('Q_3Tau')"
            :setUntil="'S'"
            :setMin="60"
            :setMax="600"
            :setValue.sync="Q3TauValue"
            :subOption="'Q_3Tau'"
            v-if="safety==1"
          ></tstartVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('H/LVRTFunction')" name="4">
          <enablepublicVue
            :subOption="'H/LVRT'"
            :columns="toggleArr"
            :setValue="LocalArr.HLVRTFunctionValue"
          ></enablepublicVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('ExportControl')" name="5">
          <languageVue
            :setName="$t('ExportControl')"
            :columns="toggleArr"
            :valName="'wMeterTypeValue'"
            :subOption="'wMeterType'"
            :setValue="LocalArr.exportEnableCode"
            @getFormData="setExportEnable"
          ></languageVue>
          <pfLockInPointVue
            :setName="$t('UserValue')"
            :setUntil="'W'"
            :setMin="0"
            :setMax="60000"
            :valName="'ExportLimitValue'"
            :subOption="'ExportLimit'"
            :setValue.sync="ExportLimitValue"
            v-if="isExportControl"
          ></pfLockInPointVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('PVConnection')" name="6" style="display:none">
          <languageVue
            :columns="pvConnectArr"
            :valName="'PvModeValue'"
            :subOption="'PvMode'"
            :setValue="LocalArr.PvModeCode"
          ></languageVue>
        </van-collapse-item>
        <van-collapse-item title="DRM Function" name="7" v-if="safety==2||safety==22">
          <enablepublicVue
            :subOption="'wAS4777PowerManagerEnable'"
            :columns="toggleArr"
            :setValue="LocalArr.DRMFunctionValue"
          ></enablepublicVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('LineImpedanceEnable')" name="8" v-if="safety==2||safety==22">
          <enablepublicVue
            :columns="toggleArr"
            :setValue="LocalArr.lineImpedanceEnableCode"
            :subOption="'LineImpedanceEnable'"
            @getFormData="setLineImpedanceEnable"
          ></enablepublicVue>
          <tstartVue
            :setName="$t('LineImpedanceEnableFlag')"
            :setUntil="'Ω'"
            :setMin="0"
            :setMax="1000"
            :setValue.sync="LineImpedanceValue"
            :subOption="'LineImpedanceValue'"
            v-if="isLineImpedanceEnable"
          ></tstartVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('puFunction')" name="9" v-if="safety==2||safety==22">
          <enablepublicVue
            :setName="$t('puFunction')"
            :columns="toggleArr"
            :setValue="LocalArr.puFunctionEnableCode"
            :subOption="'puFunction'"
            @getFormData="setPuFunction"
          ></enablepublicVue>
          <vacMaxVue
            :setName="$t('SetV2')"
            :setUntil="'V'"
            :setMin="'216.0'"
            :setMax="'230.0'"
            :valName="'SetV2Value'"
            :setValue.sync="SetV2Value"
            :subOption="'SetV2'"
            v-if="isPu"
          ></vacMaxVue>
          <vacMaxVue
            :setName="$t('SetV3')"
            :setUntil="'V'"
            :setMin="'235.0'"
            :setMax="'255.0'"
            :valName="'SetV3Value'"
            :setValue.sync="SetV3Value"
            :subOption="'SetV3'"
            v-if="isPu"
          ></vacMaxVue>
          <vacMaxVue
            :setName="$t('SetV4')"
            :setUntil="'V'"
            :setMin="'244.0'"
            :setMax="'265.0'"
            :valName="'SetV4Value'"
            :setValue.sync="SetV4Value"
            :subOption="'SetV4'"
            v-if="isPu"
          ></vacMaxVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('Pfreq')" name="10" v-if="safety!=3&&safety!=4&&safety!=8&&safety!=13&&safety!=14&&safety!=15&&safety!=25&&safety!=31&&safety!=32&&safety!=33&&safety!=34&&safety!=35&&safety!=36&&safety!=37&&safety!=38">
          <enablepublicVue
            :columns="toggleArr"
            :setValue="LocalArr.pfreqEnableCode"
            :subOption="'PFreqEnable'"
            @getFormData="setPfreq"
          ></enablepublicVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('wFreqSetPoint')" name="11" v-if="isPfreq&&(safety==1||safety==6||safety==7||safety==9||safety==23||safety==24||safety==26||safety==27||safety==28||safety==29||safety==30)">
          <facMaxVue
            :setName="$t('wFreqSetPoint')"
            :setUntil="'Hz'"
            :setMin="'50.20'"
            :setMax="'51.00'"
            :valName="'wFreqSetPointValue'"
            :subOption="'wFreqSetPoint'"
            :setValue.sync="wFreqSetPointValue"
          ></facMaxVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('wFreqDroopRate')" name="12" v-if="isPfreq&&(safety==1||safety==6||safety==7||safety==9||safety==23||safety==24||safety==26||safety==27||safety==28||safety==29||safety==30)">
          <pfLockInPointVue
            :setName="$t('wFreqDroopRate')"
            :setUntil="'%'"
            :setMin="2"
            :setMax="12"
            :valName="'wFreqDroopRateValue'"
            :subOption="'wFreqDroopRate'"
            :setValue.sync="wFreqDroopRateValue"
          ></pfLockInPointVue>
        </van-collapse-item>
        <van-collapse-item title="wFreDroopDelayTime (Ms)" name="13" v-if="isPfreq&&safety==24">
          <pfLockInPointVue
            :setMin="0"
            :setMax="1000"
            :valName="'wFreDroopDelayTimeValue'"
            :subOption="'wFreDroopDelayTime'"
            :setValue.sync="wFreDroopDelayTimeValue"
          ></pfLockInPointVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('SoftStart')" name="14" v-if="safety==0||safety==1||safety==2||safety==22">
          <enablepublicVue
            :columns="toggleArr"
            :setValue="LocalArr.softStartEnableCode"
            :subOption="'SoftStartEnable'"
            @getFormData="setSoftStart"
          ></enablepublicVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('SetWgra')" name="15" v-if="isSoftStart&&(safety==2||safety==22)">
          <facMaxVue
            :setName="$t('SetWgra')"
            :setUntil="'%'"
            :setMin="'5.00'"
            :setMax="'100.00'"
            :valName="'SetWgraValue'"
            :subOption="'SetWgra'"
            :setValue.sync="SetWgraValue"
          ></facMaxVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('ConditionConn')" name="16">
          <enablepublicVue
            :subOption="'ConditionConnectEnable'"
            :columns="toggleArr"
            :setValue="LocalArr.ConditionConnValue"
          ></enablepublicVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('InverterStartStop')" name="17">
          <enablepublicVue
            :subOption="'Inverter_Start_Stop'"
            :columns="toggleArr"
            :setValue="LocalArr.InverterStartStopValue"
          ></enablepublicVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('EarthDetect')" name="18">
          <enablepublicVue
            :subOption="'EarthDetect'"
            :columns="toggleArr"
            :setValue="LocalArr.EarthDetectValue"
          ></enablepublicVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('Reset')" name="19">
          <resetINVEnergyVue :setName="$t('ClearInverterHistory')" :valName="'ClearInverterHistoryValue'" :subOption="'ClearInverterHistory'"></resetINVEnergyVue>
          <resetErrorLogsVue :setName="$t('ResetErrorLogs')" :subOption="'ResetErrorLog'"></resetErrorLogsVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('NewPassword')" name="20">
          <newPasswordVue :valName="'NewPasswordValue'" :subOption="'NewPassword'" :setValue.sync="NewPasswordValue"></newPasswordVue>
        </van-collapse-item>
      </van-collapse>
    </van-pull-refresh>
  </div>
</template>

<script>
import safetyVue from "../../../components/Safety/BDSafety";
import pfLockInPointVue from "../../../components/PfLockInPoint/BDPfLockInPoint";
import vacMaxVue from "../../../components/VacMax/BDVacMax";
import enablepublicVue from "../../../components/EnablePublic/BDEnablePublic";
import facMaxVue from "../../../components/FacMax/BDFacMax";
import vacMiddleVue from "../../../components/VacMiddle/BDVacMiddle";
import tripFreVue from "../../../components/TripFre/TripFre";
import tstartVue from "../../../components/TStart/BDTStart";
import languageVue from "../../../components/Language/BDLanguage";
import resetINVEnergyVue from "../../../components/ResetINVEnergy/BDResetINVEnergy";
import resetErrorLogsVue from "../../../components/ResetErrorLogs/BDResetErrorLogs";
import newPasswordVue from "../../../components/NewPassword/BDNewPassword";
import pfLockInPoint2Vue from '../../../components/PfLockInPoint/BDPfLockInPoint2'

export default {
  components: {
    safetyVue,
    pfLockInPointVue,
    vacMaxVue,
    enablepublicVue,
    facMaxVue,
    vacMiddleVue,
    tripFreVue,
    tstartVue,
    languageVue,
    resetINVEnergyVue,
    resetErrorLogsVue,
    newPasswordVue,
    pfLockInPoint2Vue
  },
  data() {
    return {
      isLoading: false,
      timer: "",
      activeNames: [],
      safety: sessionStorage.getItem("safety"),
      showPowerFact: false,
      factorArr: [{text:this.$t('Off'),code:0},{text:this.$t('OverExcited'),code:1},{text:this.$t('UnderExcited'),code:2},{text:this.$t('PF(P)'),code:3},{text:this.$t('Q(u)'),code:4},{text:this.$t('Q-Set'),code:5}],
      powerFactors: [],
      factMode: "",
      factModeCode: "",
      isPFP: true,
      isQu: true,
      isQSet: true,
      P2Value: "",
      P3Value: "",
      P4Value: "",
      P5Value: "",
      P6Value: "",
      PfLockInPointValue: "",
      PfLockOutPointValue: "",
      wQuVrateUpValue: "",
      wQuVrateLowValue: "",
      SetQurangeV1Value: "",
      SetQurangeV4Value: "",
      bQpower_setValue: "",
      VacMaxValue: "",
      VacMaxSlowProtectValue: "",
      VacMinValue: "",
      VacMinSlowProtectValue: "",
      Grid10MinAverageValue: "",
      FacMaxValue: "",
      FacMaxSlowProtectValue: "",
      FacMinValue: "",
      FacMinSlowProtectValue: "",
      VacMiddleSlowProtectValue: "",
      tripfreValue: "",
      tripvoltValue: "",
      lossofmainsValue: "",
      TStartValue: "",
      Q3TauValue: "",
      isExportControl: false,
      toggleArr: [this.$t('Disable'),this.$t('Enable')],
      NeutralLineArr:[this.$t('Enable'),this.$t('Disable')],
      ExportLimitValue: "",
      pvConnectArr: [this.$t('Comm'), this.$t('Multi')],
      LocalArr: {
        OV10EnableValue: "",
        FreqROCOFValue: "",
        NeutralLineValue: "",
        HLVRTFunctionValue: "",
        exportEnableCode: "",
        PvModeCode: "",
        lineImpedanceEnableCode: "",
        puFunctionEnableCode: "",
        pfreqEnableCode: "",
        DRMFunctionValue: "",
        ConditionConnValue: "",
        InverterStartStopValue: "",
        EarthDetectValue: "",
        softStartEnableCode: "",
      },
      isLineImpedanceEnable: false,
      LineImpedanceValue: "",
      isPu: false,
      SetV2Value: "",
      SetV3Value: "",
      SetV4Value: "",
      isPfreq: false,
      wFreqSetPointValue: "",
      wFreqDroopRateValue: "",
      wFreDroopDelayTimeValue: "",
      isSoftStart: false,
      SetWgraValue: "",
      NewPasswordValue: "",
    };
  },
  methods: {
    onClickLeft() {
      this.$router.push({ path: "/bdsetting"});
    },
    factModeConfirm(value, i) {
      this.showPowerFact = false;
      this.factMode = value.text;
      this.factModeCode = value.code;
    },
    fixedTwo1(val) {
      return this.comm.fixedTwo(val, 0.8, 1);
    },
    fixedTwo2(val) {
      return this.comm.fixedTwo(val, 0.9, 1);
    },
    fixedTwo3(val) {
      return this.comm.fixedTwo(val, 0, 1);
    },
    async getData() {
      this.comm.loadingShow();
      let datas = await this.SETAPI.LocalIn({'optType':'ReadSetData','pwd':sessionStorage.getItem('bdPwd')});
      if (datas!=null||datas!=undefined) {
        let dataArr = datas;
        this.safety = dataArr[4];
        sessionStorage.setItem("safety", this.safety);
        this.factModeCode = dataArr[13];
        this.factMode = this.factorArr[this.factModeCode].text;
        /*判断用户的选择*/
        if (dataArr[13] == 3) {
          this.isPFP = true;
        } else {
          this.isPFP = false;
        }
        if (dataArr[13] == 4) {
          this.isQu = true;
        } else {
          this.isQu = false;
        }
        if (dataArr[13] == 5) {
          this.isQSet = true;
        } else {
          this.isQSet = false;
        }
        this.P2Value = dataArr[14];
        this.P3Value = dataArr[15];
        this.P4Value = dataArr[16];
        this.P5Value = dataArr[17];
        this.P6Value = dataArr[18];
        this.PfLockInPointValue = dataArr[96];
        this.PfLockOutPointValue = dataArr[97];
        this.wQuVrateUpValue = dataArr[102];
        this.wQuVrateLowValue = dataArr[103];
        this.SetQurangeV1Value = dataArr[129];
        this.SetQurangeV4Value = dataArr[130];
        this.bQpower_setValue = dataArr[132];
        this.VacMaxValue = dataArr[1];
        this.VacMaxSlowProtectValue = dataArr[8];
        this.VacMinValue = dataArr[0];
        this.VacMinSlowProtectValue = dataArr[7];
        this.LocalArr.OV10EnableValue = dataArr[151];
        this.Grid10MinAverageValue = dataArr[6];
        this.FacMaxValue = dataArr[3];
        this.FacMaxSlowProtectValue = dataArr[10];
        this.FacMinValue = dataArr[2];
        this.FacMinSlowProtectValue = dataArr[9];
        this.LocalArr.FreqROCOFValue = dataArr[152];
        this.VacMiddleSlowProtectValue = dataArr[142];
        this.tripfreValue = dataArr[143];
        this.tripvoltValue = dataArr[144];
        this.lossofmainsValue = dataArr[145];
        this.TStartValue = dataArr[146];
        this.LocalArr.NeutralLineValue = dataArr[154];
        this.Q3TauValue = dataArr[157];
        this.LocalArr.HLVRTFunctionValue = dataArr[158];
        this.LocalArr.exportEnableCode = dataArr[135];
        /*判断用户的选择*/
        if (dataArr[135] == 1) {
          this.isExportControl = true;
        } else {
          this.isExportControl = false;
        }
        this.ExportLimitValue = dataArr[63];
        this.LocalArr.PvModeCode = dataArr[5] - 1;
        this.LocalArr.DRMFunctionValue = dataArr[153];
        this.LocalArr.lineImpedanceEnableCode = dataArr[138];
        /*判断用户的选择*/
        if (this.LocalArr.lineImpedanceEnableCode == 1) {
          this.isLineImpedanceEnable = true;
        } else {
          this.isLineImpedanceEnable = false;
        }
        this.LineImpedanceValue = dataArr[139];
        this.LocalArr.puFunctionEnableCode = dataArr[131];
        /*判断用户的选择*/
        if (this.LocalArr.puFunctionEnableCode == 1) {
          this.isPu = true;
        } else {
          this.isPu = false;
        }
        this.SetV2Value = dataArr[126];
        this.SetV3Value = dataArr[127];
        this.SetV4Value = dataArr[128];
        this.LocalArr.pfreqEnableCode = dataArr[147];
        /*判断用户的选择*/
        if (this.LocalArr.pfreqEnableCode == 1) {
          this.isPfreq = true;
        } else {
          this.isPfreq = false;
        }
        this.wFreqSetPointValue = dataArr[99];
        this.wFreqDroopRateValue = dataArr[100];
        this.wFreDroopDelayTimeValue = dataArr[101];
        this.LocalArr.softStartEnableCode = dataArr[148];
        /*判断用户的选择*/
        if (this.LocalArr.softStartEnableCode == 1) {
          this.isSoftStart = true;
        } else {
          this.isSoftStart = false;
        }
        this.SetWgraValue = dataArr[125];
        this.ConditionConnValue = dataArr[149];
        this.LocalArr.InverterStartStopValue = dataArr[155];
        this.LocalArr.EarthDetectValue = dataArr[156];
        this.NewPasswordValue = this.comm.showPwd(dataArr[104]);
      } else {
        this.comm.tipsShow("InvNoResponse");
      }
    },
    //获取powerfactor列表
    getPowerFactory() {
      if (this.safety == 2 ||this.safety == 6 ||this.safety == 7 ||this.safety == 9 ||this.safety == 22 ||this.safety == 23 ||this.safety == 24 ||this.safety == 26 ||this.safety == 27 ||this.safety == 28 ||this.safety == 29 ||this.safety == 30) {
        this.powerFactors = [{ text: this.$t('Off'), code: 0 },{ text: this.$t('OverExcited'), code: 1 },{ text: this.$t('UnderExcited'), code: 2 },{ text: this.$t('PF(P)'), code: 3 },{ text: this.$t('Q(u)'), code: 4 },{ text: this.$t('Q-Set'), code: 5 }];
      } else if (this.safety == 0 || this.safety == 1) {
        this.powerFactors = [{ text: this.$t('OverExcited'), code: 1 },{ text: this.$t('UnderExcited'), code: 2 },{ text: this.$t('PF(P)'), code: 3 }];
      } else if (this.safety == 21) {
        this.powerFactors = [{ text: this.$t('Off'), code: 0 },{ text: this.$t('OverExcited'), code: 1 },{ text: this.$t('UnderExcited'), code: 2 },{ text: this.$t('Q(u)'), code: 4 },{ text: this.$t('Q-Set'), code: 5 }];
      } else {
        this.powerFactors = [{ text: this.$t('Off'), code: 0 },{ text: this.$t('OverExcited'), code: 1 },{ text: this.$t('UnderExcited'), code: 2 }];
      }
    },
    //设置安规
    setSafety(data){
      if(data=='success'){
        this.safety=sessionStorage.getItem('safety');
        this.getPowerFactory();
      }
    },
    //设置powerfactor
    async powerfactorSubmit() {
      //处理数据
      let factorData_new = {};
      factorData_new.optType = "PowerFactor";
      factorData_new.pwd = localStorage.getItem("bdPwd");
      factorData_new.P1Value = this.factModeCode;
      if (this.P2Value != null && this.P2Value != undefined) {
        factorData_new.P2Value = this.comm.mulFunction(this.P2Value,100);
      }
      if (this.P3Value != null && this.P3Value != undefined) {
        factorData_new.P3Value = this.comm.mulFunction(this.P3Value,100);
      }
      if (this.P4Value != null && this.P4Value != undefined) {
        factorData_new.P4Value = this.comm.mulFunction(this.P4Value,100);
      }
      if (this.P5Value != null && this.P5Value != undefined) {
        factorData_new.P5Value = this.comm.mulFunction(this.P5Value,100);
      }
      if (this.P6Value != null && this.P6Value != undefined) {
        factorData_new.P6Value = this.comm.mulFunction(this.P6Value,100);
      }
      this.comm.loadingShow();
      let data = await this.SETAPI.LocalIn(factorData_new);
      let newdata = data.substring(0,1);
      if (newdata == "Y") {
        this.comm.toastSuccess();
        /*判断用户的选择*/
        if (this.factModeCode == 3) {
          this.isPFP = true;
        } else {
          this.isPFP = false;
        }
        if (this.factModeCode == 4) {
          this.isQu = true;
        } else {
          this.isQu = false;
        }
        if (this.factModeCode == 5) {
          this.isQSet = true;
        } else {
          this.isQSet = false;
        }
      } else {
        this.comm.toastFail();
      }
    },
    //设置Export Enable
    setExportEnable(data) {
      /*判断用户的选择*/
      if (data == 1) {
        this.isExportControl = true;
      } else {
        this.isExportControl = false;
      }
    },
    //设置LineImpedanceEnable
    setLineImpedanceEnable(data) {
      /*判断用户的选择*/
      if (data == 1) {
        this.isLineImpedanceEnable = true;
      } else {
        this.isLineImpedanceEnable = false;
      }
    },
    //设置PU Function
    setPuFunction(data) {
      /*判断用户的选择*/
      if (data == 1) {
        this.isPu = true;
      } else {
        this.isPu = false;
      }
    },
    //设置Pfreq
    setPfreq(data) {
      /*判断用户的选择*/
      if (data == 1) {
        this.isPfreq = true;
      } else {
        this.isPfreq = false;
      }
    },
    //设置SoftStart
    setSoftStart(data) {
      /*判断用户的选择*/
      if (data == 1) {
        this.isSoftStart = true;
      } else {
        this.isSoftStart = false;
      }
    },
    onRefresh() {
      this.isLoading = false;
      this.timer = new Date().getTime();
      for (let i in this.LocalArr) {
        this.LocalArr[i] = "";
      }
      this.getData();
      this.getPowerFactory();
    },
  },
  mounted() {
    setTimeout(()=>{
      this.getData();
      this.getPowerFactory();
    },1000);
  },
};
</script>

<style scoped lang="less">
</style>
